export function initEvent(speed = 3){
    const nav = document.querySelector('nav');
    const logo = nav.querySelector('.logo');
    const vdBox = document.querySelector('.fixed_box')
    const container = document.querySelector('.container')
    const wrap = container.querySelector('.wrap')

    if (container.getBoundingClientRect().top <= nav.clientHeight) {
        nav.className = 'nav_active';
        logo.setAttribute('src', 'https://project-jiu-files-1308151379.cos.ap-guangzhou.myqcloud.com/project-mayi/mayi_logo_active.svg')
    }

    let scrollY = window.scrollY;
    window.onscroll = () => {
        vdBox.style['transform'] = `translateY(-${window.scrollY / speed + 'px'})`;

        let curScrollY = window.scrollY;
        if (curScrollY > scrollY) {
            nav.style['top'] = '-100%';
            nav.setAttribute('data-visible', 'true')
        } else {
            nav.style['top'] = '0';
            nav.setAttribute('data-visible', 'false')
        }
        scrollY = curScrollY;

        if (nav.dataset.visible && container.getBoundingClientRect().top <= nav.clientHeight) {
            nav.className = 'nav_active';
            logo.setAttribute('src', 'https://project-jiu-files-1308151379.cos.ap-guangzhou.myqcloud.com/project-mayi/mayi_logo_active.svg')
        } else {
            nav.className = '';
            logo.setAttribute('src', 'https://project-jiu-files-1308151379.cos.ap-guangzhou.myqcloud.com/project-mayi/mayi_logo.svg')
        }
    }
}